package lj.jdbctest.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author lj
 * @Description: 快速入门
 * @date 2020-11-23 13:02
 * @QQ 851477108
 */


public class jdbc {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1. 导入驱动jar包
        //2.注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //3.获取数据库连接对象
//        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db3","root","root");
        Connection conn = DriverManager.getConnection("jdbc:mysql:///db3","root","root");
        //4.定义sql语句
        String sql = "update account set balance = 100 where id = 1";
        //5.获取执行sql的对象 Statement
        Statement statement = conn.createStatement();
        //6.执行sql
        int count = statement.executeUpdate(sql);
        //7.处理结果,返回1表示处理的次数
        System.out.println(count);
        //8.释放资源
        statement.close();
        conn.close();
    }
}
